/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#include <cassert>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>

#include "se_defines.h"

SE_GLOBALS()

#define NAMES_LEN 0x30

struct Obj {
  char name[NAMES_LEN];
  char buf[8];
  unsigned int val;
};

void test_case(std::string content) {
  std::istringstream iss(content);
  std::vector<std::string> names(
      (std::istream_iterator<std::string>(iss)),
      std::istream_iterator<std::string>());

  Obj obj;
  memset(&obj, 0x0, sizeof(Obj));
  int bytes_off = 0;

  for (const auto& name : names) {
    bytes_off += snprintf(
        obj.name + bytes_off, NAMES_LEN - bytes_off, "%s,", name.c_str());
  }

  if (obj.val == 0xdeadbeef) {
    SE_TARGET_STATE(true);
  }
}

int main(int argc, char* argv[]) {
  std::istream* input;
  std::ifstream file;
  if (argc < 2) {
    input = &std::cin; // No file name provided, read from stdin
  } else {
    file.open(argv[1]);
    if (!file) {
      std::cerr << "Could not open the file.\n";
      return 1;
    }
    input = &file; // File opened successfully, read from file
  }
  std::string content(
      (std::istreambuf_iterator<char>(*input)),
      std::istreambuf_iterator<char>());
  test_case(content);
  return 0;
}
